package com.qf.login;

import com.qf.bo.RoleBO;
import com.qf.bo.UserBO;
import com.qf.bo.UserDetailsBO;
import com.qf.dao.UserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;


/**
 * 自定义用户类
 *
 * @USER: Administrator
 * @DATE: 2025/8/30 下午2:11
 * @VERSION: 1.0.0
 */
@Service
public class UserService implements UserDetailsService {

    @Autowired
    private UserDao userDao;

    @Autowired
    private PasswordEncoder passwordEncoder;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        UserBO userBO = userDao.queryUserByName(username);
        if (userBO == null) {
            throw new UsernameNotFoundException("用户名不存在");
        }

        return new UserDetailsBO(userBO);
    }
}
